package com.boot2.core.web.xss;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;


/**
 * @author zhangweilin
 * @date 2019/1/16 20:11
 * @description: Bean的批量注入 使用自定义 ImportSelector 须实现 ImportSelector
 * 接口，返回值必须是class全称的String[]，该String[]的所有类都将被Spring IOC容器统一管理
 */
//@Component
//@Import(value = {XssHttpServletFilterImportSelector.class})
public class XssHttpServletFilterImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
//        Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableXssHttpServletFilter.class.getName());
//        if (annotationAttributes == null) {
//            return null;
//        }
//        if ( annotationAttributes.toString().contains("onlySale")) {
//            return new String[]{Sales.class.getName()};
//        }
        boolean annotated = importingClassMetadata.isAnnotated(EnableXssHttpServletFilter.class.getName());
        if (annotated) {
            return new String[]{XssHttpServletFilter.class.getName()};
        }
        return null;
    }
}